//
//  XBookkeepingSectionHeaderView.m
//  iAccountBook
//
//  Created by 侯伟 on 2021/9/23.
//

#import "XBookkeepingSectionHeaderView.h"

@interface XBookkeepingSectionHeaderView ()

@property(nonatomic,weak)MyLinearLayout* contentLayout;

@end

@implementation XBookkeepingSectionHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithReuseIdentifier:reuseIdentifier]){
        self.backgroundColor = COLOR_BACKGEOUND;
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews{
    
    MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:(MyOrientation_Horz)];
    contentLayout.padding = UIEdgeInsetsMake(0, 16,0, 16);
    contentLayout.myMargin = 0;
    contentLayout.myHeight = PX(44);
    contentLayout.subviewHSpace = 10;
    contentLayout.gravity = MyGravity_Horz_Between;
    contentLayout.cacheEstimatedRect = YES;
    [self.contentView addSubview:contentLayout];
    _contentLayout = contentLayout;

    UILabel* timeLb = [UILabel lableWithFont:FONT_FIT(15) color:COLOR_GRAY_BASE text:@"--"];
    timeLb.myLeft = 0;
    timeLb.myCenterY = 0;
    [contentLayout addSubview:timeLb];
    _timeLb = timeLb;

    UILabel* amtLb = [UILabel lableWithFont:NUMBERFONT_FIT(15) color:COLOR_GREEN text:@"￥0.00"];
    amtLb.textAlignment = NSTextAlignmentRight;
    amtLb.myRight = amtLb.myCenterY = 0;
    [contentLayout addSubview:amtLb];
    _amtLb = amtLb;
}

#pragma private -- Size

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority{
    
    CGSize cellSize = CGSizeZero;
    if (@available(iOS 11.0, *)) {
        cellSize = [self.contentLayout sizeThatFits:CGSizeMake(targetSize.width - self.safeAreaInsets.left - self.safeAreaInsets.right, targetSize.height)];
    } else {
        CGSize size = targetSize;
        size.width = size.width;
        cellSize = [self.contentLayout sizeThatFits:size];  //如果使用系统自带的分割线，请记得将返回的高度height+1
    }
    return cellSize;
}
@end
